<?php
/**
 * Created by PhpStorm.
 * User: HuangLuSen
 * Date: 2017/5/19
 * Time: 14:26
 */

namespace app\admin\controller;


use app\admin\model\Users;
use app\common\model\Wesmslog;
use app\common\traits\Page;
use think\Db;
use app\common\model\Order_log;

class Log extends Admin
{
   use Page;
    public function index()
    {
        $map = [];
        $order_id = input('order_id');
        if ($order_id) {
            $map['order_id'] = $order_id;
        }
        $log_type = input('log_type');
        if ($log_type) {
            $map['log_type'] = $log_type;
        }
        $is_success = input('is_success');
        if ($is_success) {
            $map['is_success'] = $is_success;
        }
        $send_id = input('send_id');
        if ($send_id) {
            $map['send_id'] = $send_id;
        }
        $receive_id = input('receive_id');
        if ($receive_id) {
            $map['receive_id'] = $receive_id;
        }
        $this->getUSers();
        $user_list = $this->pageshow('wesmslog',$map);
        return $this->fetch('index', ['wesmslog' => $user_list,'map'=>$map]);
    }

    public function getUSers()
    {
       $user= Users::where(['status'=>1])->field('id,username')->select();
       $this->assign('user',$user);
    }
    public function log()
    {
        $map = [];
        $order_id = input('order_id');
        if ($order_id) {
            $map['order_id'] = $order_id;
        }
        $log_type = input('log_type');
        if ($log_type) {
            $map['log_type'] = $log_type;
        }
        $user_list = $this->pageshow('wesmslog',$map);
        return $this->fetch('yewu/log', ['wesmslog' => $user_list,'map'=>$map]);
    }


    public function order_All_Log(){
        $order_log        = new Order_log();
        $where = [];
        $data = $this->request->param();
        if(!empty($data['order_id'])){
            $where['order_id | maphone '] = trim($data['order_id']);
        }
        if(!empty($data['khd'])){
            $where['khd'] = $data['khd'];
        }
        if(!empty($data['operation'])){
            $where['operation'] = $data['operation'];
        }
        $this->assign('map',$data);

        $count = $order_log->where($where)->count();// 查询满足要求的总记录数
        $Page = new \page\Page($count, 20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $Page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');//定义分页类的的主题
        $show = $Page->newshow();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $order_log->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->assign('page', $show);
        $this->assign('list', $list);
        $this->get_Log_Map_Data();
        return $this->fetch('order_log');
    }

    public function get_Log_Map_Data(){
        $khd = Order_log::Khd();
        $operation = Order_log::Operation();

        $this->assign('khd',$khd);
        $this->assign('operation',$operation);
    }
}